import { Injectable } from '@angular/core'
import { deepCopy } from '@delon/util'

import { ObservableStore } from '@shared/classes/ObservableStoreClass'
import { StoreCreate, Store } from '@shared/interfaces/store'

/* 门店(store)数据管理(store)服务(service) */
@Injectable()
export class StoreDataService extends ObservableStore<StoreCreate> {
  constructor() {
    super(new StoreCreate())
  }

  public store$: ObservableStore<Store> = new ObservableStore(new Store())

  updateValue(store: StoreCreate): void {
    const value = deepCopy(this.value)
    Object.assign(value, store)
    this.setValue(value)
  }

  reset(): void {
    this.setValue(new StoreCreate())
  }

  setStore(data: Store) {
    this.store$.setValue(data)
  }

  resetStore() {
    this.store$.setValue(new Store())
  }
}
